//
//  DHStatus.swift
//  Weibo
//
//  Created by Holfioo on 15/9/7.
//  Copyright © 2015年 Holfioo. All rights reserved.
//

import UIKit

class DHStatus: NSObject {
    // 发布时间
    var created_at: String?
    // ID 微博
    var id: Int = 0
    // 微博内容
    var text: String?
    // 微博来源
    var source: String?
    // 图片数组
    var pic_urls: [[String: String]]?
    
    var user: DHUser?
    // 转发微博的模型
    var retweeted_status: DHStatus?
    
    // 构造函数，字典转模型
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    // 忽略多余的键值
    override func setValue(value: AnyObject?, forUndefinedKey key: String) { }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            // 字典转模型
            user = DHUser(dict: value as! [String: AnyObject])
            // 直接返回。否则会造成依旧是字典
            return
        }
        // 如果key是转发微博的话，那么进行字典转模型
        if key == "retweeted_status" {
            retweeted_status = DHStatus(dict: value as! [String: AnyObject])
            return
        }
        super.setValue(value, forKey: key)
    }
    
    // 重写描述方法
    override var description: String {
        let keys = ["created_at", "id", "text", "source", "user", "pic_urls", "retweeted_status"]
        return dictionaryWithValuesForKeys(keys).description
    }
}
